package com.kmg.scart.model;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

public class Order extends ApplicationEntity{

	private Address billingAddress;
	
	private Address shippingAddress;
	
	private User owner;
	
	private OrderStatus orderStatus;
	
	private PaymentType paymentMode;

	private Date orderDate;
	
	private Set<OrderItem> orderItems = new HashSet<OrderItem>(0);
	
	public Address getBillingAddress() {
		return billingAddress;
	}

	public void setBillingAddress(Address billingAddress) {
		this.billingAddress = billingAddress;
	}

	public Address getShippingAddress() {
		return shippingAddress;
	}

	public void setShippingAddress(Address shippingAddress) {
		this.shippingAddress = shippingAddress;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public OrderStatus getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(OrderStatus orderStatus) {
		this.orderStatus = orderStatus;
	}

	public PaymentType getPaymentMode() {
		return paymentMode;
	}

	public void setPaymentMode(PaymentType paymentMode) {
		this.paymentMode = paymentMode;
	}
	
	private void addToOrder(CartItem ci){
		OrderItem item = new OrderItem();
		item.setPrice(ci.getProduct().getPrice());
		item.setProduct(ci.getProduct());
		item.setQty(ci.getQty());
		orderItems.add(item);
	}
	
	public void checkoutFromCart(Cart cart){
		for(CartItem item:cart.getItems()){
			addToOrder(item);
		}
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
}
